package org.flower.web.servlet;

import org.flower.entity.User;
import org.flower.service.UserService;
import org.flower.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(value = "/UpdateUserPwdServlet.shtml")
public class UpdateUserPwdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = (User) request.getSession().getAttribute("user");
        UserService userService = new UserServiceImpl();
        String xinmima = request.getParameter("xinmima");
        user.setId(user.getId());
        user.setPwd(xinmima);
        if(userService.UpdatePwd(user)){
            request.removeAttribute("user");
            response.sendRedirect("PersonalCenter.jsp");
        }else{
            response.sendRedirect("PersonalCenter.jsp");
        }
    }
}
